package com.zsyc.controller;

import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.Parent;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.control.Alert.AlertType;
import java.io.*;
import java.util.logging.Logger;
import java.util.logging.Level;
import java.util.prefs.Preferences;

public class SettingsController {
    
    private static final Logger LOGGER = Logger.getLogger(SettingsController.class.getName());
    private static final String PREF_NODE = "com.zsyc.settings";
    
    private Preferences prefs;
    private Stage primaryStage;
    private MainController mainController;
    
    @FXML
    public void initialize() {
        prefs = Preferences.userRoot().node(PREF_NODE);
        LOGGER.info("设置控制器初始化完成");
    }
    
    @FXML
    private void goBack() {
        if (mainController != null) {
            mainController.showMainView();
        } else {
            LOGGER.warning("主控制器引用为空，无法返回主页");
        }
    }
    
    public void setPrimaryStage(Stage stage) {
        this.primaryStage = stage;
    }
    
    public void setMainController(MainController mainController) {
        this.mainController = mainController;
    }
    
    private void showInfo(String title, String content) {
        Alert alert = new Alert(AlertType.INFORMATION);
        alert.setTitle("信息");
        alert.setHeaderText(title);
        alert.setContentText(content);
        alert.showAndWait();
    }
    
    private void showError(String title, String content) {
        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle("错误");
        alert.setHeaderText(title);
        alert.setContentText(content);
        alert.showAndWait();
    }
}
